home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-02-07 | 4.5 KB | 157 lines | [TEXT/MPS ] |
- (*
- CTBDispose [tool] -- Dispose of the tool indicated ("connection", "terminal", "file transfer"), closing
- the connection if necessary. If tool is "all", then dispose of all tools.
-
- To compile and link this file using Macintosh Programmer's Workshop,
-
- pascal -w CTBDispose.p
- link -m ENTRYPOINT -o HyperCommands -rt XCMD=2756 -sn Main=CTBDispose ∂
- CTBClose.p.o "{MPW}"Libraries:interface.o "{MPW}"Libraries:Libraries:HyperXLib.o
-
- © Copyright 1990 by Apple Computer, Inc.
-
- Initial coding 2/90 by Harry R. Chesley.
- *)
-
- {$R-}
-
- {$S CTBDispose } { Segment name must be the same as the command name. }
-
- unit DummyUnit;
-
- interface
-
- uses MemTypes, QuickDraw, OSIntf, ToolIntf, CTBUtils, FTIntf, CMIntf, TMIntf, CRMIntf, HyperXCmd;
-
- procedure EntryPoint(paramPtr: XCmdPtr);
-
- implementation
-
- procedure CTBDispose(paramPtr: XCmdPtr); forward;
-
- procedure EntryPoint(paramPtr: XCmdPtr);
-
- begin
- CTBDispose(paramPtr);
- end;
-
- procedure CTBDispose(paramPtr: XCmdPtr);
-
- {$I CTBUtil.inc}
-
- var i, j: integer;
- tt: ToolType;
- doToAll: boolean;
- sizes: CMBufferSizes;
- status: CMStatFlags;
- err: CMErr;
- cHand: ConnHandle;
- theHand: ConnHandle;
- theBuf: InputBufferHandle;
- h: Handle;
- gWind: WindowPtr;
-
- procedure Fail(errMsg: Str255); { set theResult and quit }
- begin
- paramPtr^.returnValue := PasToZero(paramPtr,errMsg);
- exit(CTBDispose);
- end;
-
- begin
- { Check the parameter count. }
- if paramPtr^.paramCount > 1 then Fail('Invalid parameter count');
-
- { Check that the Comm Toolbox is present. }
- CTBReady;
-
- { Figure out what to dispose of. }
- if not ParmPresent(1) then doToAll := true
- else if (Chr(paramPtr^.params[1]^^) = 'a') or (Chr(paramPtr^.params[1]^^) = 'A') then doToAll := true
- else doToAll := false;
-
- { All tools or just one? }
- if doToAll then
- begin
- { Dispose of everything in the outstanding tool list. }
- for i := 1 to Globals^^.allToolsSize do
- case Globals^^.allTools[i].tType of
- connectionTool:
- begin
- cHand := Globals^^.allTools[i].cHand;
- if CMStatus(cHand,sizes,status) <> noErr then
- if Band(status,cmStatusOpen+cmStatusOpening) <> 0 then
- err := CMClose(cHand,false,nil,3600,true);
- theBuf := InputBufferHandle(CMGetUserData(cHand));
- if theBuf^^.termString <> nil then DisposHandle(theBuf^^.termString);
- DisposHandle(Handle(theBuf));
- CMDispose(cHand);
- end;
- terminalTool:
- begin
- h := Handle(TMGetUserData(Globals^^.allTools[i].tHand));
- gWind := Globals^^.allTools[i].tHand^^.owner;
- TMDispose(Globals^^.allTools[i].tHand);
- CloseWindow(gWind);
- DisposHandle(h);
- end;
- fileTransferTool: FTDispose(Globals^^.allTools[i].ftHand);
- end;
- DeallocateGlobals;
- end
- else
- begin
- tt := GetToolTypeParm(1);
- theHand := nil;
- case tt of
- connectionTool:
- if Globals^^.connHand <> nil then
- begin
- cHand := Globals^^.connHand;
- if CMStatus(cHand,sizes,status) <> noErr then
- if Band(status,cmStatusOpen+cmStatusOpening) <> 0 then
- err := CMClose(cHand,false,nil,3600,true);
- theBuf := InputBufferHandle(CMGetUserData(cHand));
- if theBuf^^.termString <> nil then DisposHandle(theBuf^^.termString);
- DisposHandle(Handle(theBuf));
- CMDispose(cHand);
- theHand := cHand;
- Globals^^.connHand := nil;
- end;
- terminalTool:
- if Globals^^.termHand <> nil then
- begin
- h := Handle(TMGetUserData(Globals^^.termHand));
- gWind := Globals^^.termHand^^.owner;
- TMDispose(Globals^^.termHand);
- CloseWindow(gWind);
- DisposHandle(h);
- theHand := ConnHandle(Globals^^.termHand);
- Globals^^.termHand := nil;
- end;
- fileTransferTool:
- if Globals^^.FTHand <> nil then
- begin
- FTDispose(Globals^^.FTHand);
- theHand := ConnHandle(Globals^^.FTHand);
- Globals^^.FTHand := nil;
- end;
- end;
- { If we succeeded in disposing of something, take it out of the outstanding tool list too. }
- if theHand <> nil then
- begin
- j := 1;
- for i := 1 to Globals^^.allToolsSize do
- if Globals^^.allTools[i].cHand <> theHand then
- begin
- Globals^^.allTools[j] := Globals^^.allTools[i];
- j := j+1;
- end;
- Globals^^.allToolsSize := Globals^^.allToolsSize-1;
- SetHandleSize(Handle(Globals),sizeof(OurGlobalType)-sizeof(ToolArray)+
- Globals^^.allToolsSize*sizeof(OneToolType))
- end;
- end;
- end;
-
- end.
-